package com.dongdongshop.controller;

import com.dongdongshop.admin.vo.AreaVO;
import com.dongdongshop.admin.vo.CitiesVO;
import com.dongdongshop.admin.vo.ProvincesVO;
import com.dongdongshop.common.Result;
import com.dongdongshop.service.ProvincesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("pres")
public class ProvincesController {
    @Autowired
    private ProvincesService provincesService;

    @PostMapping
    public Result getById(@RequestParam String id,@RequestParam String name){
        if (name.equals("one")){
            List<ProvincesVO> provincesVO = provincesService.getByprovinceid();
            return Result.OK().setData(provincesVO);
        }else if (name.equals("two")){
            List<CitiesVO> citiesVO = provincesService.getBycitiesid(id);
            return Result.OK().setData(citiesVO);
        }else {
            List<AreaVO> areaVO = provincesService.getByareaid(id);
            return Result.OK().setData(areaVO);
        }
    }
}
